<?php
/**
 * Created by PhpStorm.
 * User: hjc19850430@gmail.com
 * Date: 2016/3/8
 * Time: 11:13
 * FileName: BaseService.class.php
 * ProjectName: wap_greencampus
 */

class BaseService 
{
    public function __construct()
    {
        $this->_initialize();
    }

    public function _initialize()
    {
        
    }

    public function __set($name, $value)
    {
        $this->$name = $value;
    }

    public function __get($name)
    {
        return $this->$name;
    }

    /**
     * 两个对象间复制属性值 ，当一个属性在两边都存在时才复制
     * 属性值是NULL也会复制
     *
     * @param mixed $src 数据源，数组|对象
     * @param string $des 目标数据
     * @return Object 返回对象本身
     */
    public function setProperties($src)
    {
        $src_vars = is_object($src) ? get_object_vars($src) : $src;
        foreach ($src_vars as $name => $value) {
            if (property_exists($this, $name)) {
                $this->$name = $value;
            }
        }

        //return $this;
    }

    public function getMeeting($meetingId) { //当前账号相关信息
        $condition = array(
            'meeting_id' => $meetingId,
        );
        $data = D('Meeting')->where($condition)->find();
        if($data) {
            return $data;
        }
        return false;
    }

    public function dataUrlEncode($data){ //保存当前页面的信息到cookie中。
        if($data) {
            $dataArr = array();
            foreach ($data as $key => $value) {
                foreach($value as $k => $v) {
                    $dataArr[$key][$k] = urlencode($v);
                }
            }
            return $dataArr;
        }
        return false;
    }

    public function dataUrlDecode($data){ //保存当前页面的信息到cookie中。
        if($data) {
            $dataArr = array();
            foreach ($data as $key => $value) {
                foreach($value as $k => $v) {
                    $dataArr[$key][$k] = urldecode($v);
                }
            }
            return $dataArr;
        }
        return false;
    }
    public function urlEncode($data){ //保存当前页面的信息到cookie中。
        if($data) {
            $dataArr = array();
            foreach ($data as $key => $value) {
                $dataArr[$key] = urlencode($value);
            }
            return $dataArr;
        }
        return false;
    }

    public function urlDecode($data){ //保存当前页面的信息到cookie中。
        if($data) {
            $dataArr = array();
            foreach ($data as $key => $value) {
                $dataArr[$key] = urldecode($value);
            }
            return $dataArr;
        }
        return false;
    }


    public function __destruct()
    {
        
    }
}